package com.longrise.android.byjk.plugins.tabfirst.news;

import android.webkit.JavascriptInterface;

import com.longrise.common.base.RxManager;
import com.longrise.common.base.web.BaseWebActivity;
import com.longrise.common.base.web.BaseWebBridge;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by callxkj on 2017/10/18.
 * 新闻详情
 */

public class NewsDetail2Bridge extends BaseWebBridge {
    private NewsDetail2Activity  mActivity;

    public NewsDetail2Bridge(BaseWebActivity activity, RxManager rxManager) {
        super(activity, rxManager);
        this.mActivity = (NewsDetail2Activity) activity;
    }


    @JavascriptInterface
    public void showCommentBox() {
        Disposable subscribe = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("");
                e.onComplete();
            }
        }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        mActivity.showComDialog();
                    }
                });
        mRxManager.addDisposable(subscribe);
    }

    //web端调用用于跳转到批量购买界面
    @JavascriptInterface
    public void toplgm() {
        Disposable subscribe = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("");
                e.onComplete();
            }
        }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        mActivity.jump2BatchbuyActivity();
                    }
                });
        mRxManager.addDisposable(subscribe);
    }

}
